   //返回上一页
   var go_to_equipment_euip = function(){
	    var url = base+"/projectCenter/businessdata/equipmentEquip/"+project_id;
	    $.get(url, function(result){
	  	   $(".layui-show").html("");
	 	   $(".layui-show").html(result);
	    });

   }
   
   var initData = function(num){
	    var param = {
			page_num:num,
			page_size:"10",
			equipment_equip_id:equip_id
	    }
		$.ajax({
	        url: base + "/projectCenter/businessdata/findListByEquipmentEquipId",
	        data: param,
	        async:false,
	        success: function (data, textStatus, jqXHR) {
	        	if(data != null){
	        		//alert(JSON.stringify(data.list));
		        	var pageCount = data.pager.pageCount;
		        	var dataObj ={
		        			"list":data.list,
		         			"dataTool":{
		         				"title":{
		          			      	"equipment_name": "设备名称"
		          			      	,"equipment_num": "设备数量"
		          			      	/*,"equipment_manufacturer_name":"设备厂商"*/
		          			      	,"equipment_price":"设备单价"
		          			        ,"equipment_num_for_185":"185号文件对设备要求"
		          			        ,"comment":"备注"
		          			      	,"update_time":"修改时间"
		          			      	,"operation":"操作"
		            			},
		            			"titleCheckbox":false,
		            			/*"equipment_require":{"field":"equipment_num_for_185"},//开启185号文件对设备的要求信息
*/								"btn":[{"event":"updateObj","name":"编辑"},
								       {"event":"equipmentSelection","name":"设备选型"},
								       {"event":"delObj","name":"删除"},
								       {"event":"equipmentInfo","name":"查看设备详情"}]
							}
			  		};
		        	showPageTable('view', dataObj,num,pageCount,"initData");
		        	equipment_require_init();
	        	}
	        },
	        error: function () {
	        }
	    });
}
   
   //添加设备数量
   var addData = function(){
	   var contentDIV = function(){
		   var content;
		   var data = {
				   "title":{
					   "equipment_type_id":"设备类型",
					   "equipment_cid_type_id":"设备子类型",
					   "equipment_id":"设备",
					   "equipment_num":"设备数量"
				   },"text":{
					   "equipment_type_id":"",
					   "equipment_cid_type_id":"",
					   "equipment_id":"",
					   "equipment_num":""
				   },"input":{
					   "equipment_type_id":"select",
					   "equipment_cid_type_id":"new_select",
					   "equipment_id":"search_select",
					   "equipment_num":"text"
				   },"input_init":{
				   }
		   };
		   var getDiv = dc_update.innerHTML;
		   laytpl(getDiv).render(data,function(html){
			   content = html;
		   });
		   return content;
	   }
	   layopen(contentDIV());
	   initEquipemntType();
	   chanageEquipmentType();
	   chanageEquipmentCidType();
   }
   
   //查看设备详情页
   var equipmentInfo = function(obj){
	    var equipment_manufacturer_id = obj.equipment_manufacturer_id;
	    var equipment_id = obj.equipment_id;
	    if(equipment_manufacturer_id == "" || equipment_manufacturer_id == "null"){
	    	layer.msg('请先进行设备选型!', {icon: 0,time:2000});
	    	return false;
	    }
	    //厂商id,设备ID
	    var url = base+"/projectCenter/businessdata/equipmentBasics/"+equipment_manufacturer_id+"/"+equipment_id+"/"+equip_id;
	    $.get(url, function(result){
		   $("#mention_data").html("");
		   $("#mention_data").html(result);
	    });
   }
   
   var searchData = function(){
	   var num = 1;
	   searchInfo(num)
   }
   //按名称搜索结果
   var searchInfo = function(num){
	   var searchName = $.trim($("#searchName").val());
	    var param = {
				page_num:num,
				page_size:"10",
				equipment_equip_id:equip_id,
				searchName:searchName
		    }
			$.ajax({
		        url: base + "/projectCenter/businessdata/findListByEquipmentEquipId",
		        data: param,
		        async:false,
		        success: function (data, textStatus, jqXHR) {
		        	if(data != null){
			        	var pageCount = data.pager.pageCount;
			        	var dataObj ={
			        			"list":data.list,
			         			"dataTool":{
			         				"title":{
			          			      	"equipment_name": "设备名称"
			          			      	,"equipment_num": "设备数量"
			          			      /*	,"equipment_manufacturer_name":"设备厂商"*/
			          			      	,"equipment_price":"设备单价"
			          			      	,"equipment_num_for_185":"185号文件对设备要求"
			          			      	,"comment":"备注"
			          			      	,"update_time":"修改时间"
			          			      	,"operation":"操作"
			            			},
			            			"titleCheckbox":false,
									"btn":[{"event":"updateObj","name":"编辑"},
									       {"event":"equipmentSelection","name":"设备选型"},
									       {"event":"delObj","name":"删除"},
									       {"event":"equipmentInfo","name":"查看设备详情"}]
								}
				  		};
			        	showPageTable('view', dataObj,num,pageCount,"searchInfo");
			        	equipment_require_init();
		        	}
		        },
		        error: function () {
		        }
		    });
	   
   }
   
   //初始化设备类型
   var initEquipemntType = function(){
	   $.post(base+"/dataCenter/businessdata/findEquipmentType",{},
	   		  	function(data,status){
    		    	if(data != null && data.list != null){
  	      		  	 var optionstring = "";
  	                 $.each(data.list, function(i,item){
  	                	optionstring += "<option value=\"" + item.id + "\" >" + item.equipment_type_name + "</option>";
  	                });
  	                $("select[name='equipment_type_id']").html('<option value=""></option>' + optionstring);
  	      		}else{
  	      		  	$("select[name='equipment_type_id']").html('<option value=""></option>');
  	      		}
    		    form.render(); 
	  });
   }
   
   var chanageEquipmentType = function(){
  		form.on("select(select)",function(value){
   			var equ_type_id = value.value;
   			initEquipmentCidType(equ_type_id);
   		});
   }
   
   //初始化设备子类型
   var initEquipmentCidType = function(equipment_type_id){
	   $.post(base+"/dataCenter/businessdata/findEquipmentCidTypeList",{equipment_type_id:equipment_type_id},
	   		  	function(data,status){
   		    	if(data != null && data.list != null){
 	      		  	 var optionstring = "";
 	                 $.each(data.list, function(i,item){
 	                	optionstring += "<option value=\"" + item.id + "\" >" + item.equipment_children_type_name + "</option>";
 	                });
 	                $("select[name='equipment_cid_type_id']").html('<option value=""></option>' + optionstring);
 	      		}else{
 	      		  	$("select[name='equipment_cid_type_id']").html('<option value=""></option>');
 	      		}
   		    form.render(); 
	  });
   }
   
   //监听子类型下拉
   var chanageEquipmentCidType = function(){
 		form.on("select(new_select)",function(value){
   			var equ_cid_type_id = value.value;
   			initEquipmentInfo(equ_cid_type_id);
   		});
	   
   }
   
   //初始化设备
   var initEquipmentInfo = function(equipment_cid_type_id){
	   $.post(base+"/dataCenter/businessdata/findEquipmentPageList",{equipment_children_type_id:equipment_cid_type_id},
	   		  	function(data,status){
  		    	if(data != null && data.list != null){
	      		  	 var optionstring = "";
	                 $.each(data.list, function(i,item){
	                	optionstring += "<option value=\"" + item.id + "\" >" + item.equipment_name + "</option>";
	                });
	                $("select[name='equipment_id']").html('<option value=""></option>' + optionstring);
	      		}else{
	      		  	$("select[name='equipment_id']").html('<option value=""></option>');
	      		}
  		    form.render(); 
	  });
   }
   
   var updateObj = function(obj){
	   var contentDIV = function(){
		   var content;
		   var data = {
				   "title":{
					   "id":"id",
					   "equipment_name":"设备名称",
					   "equipment_num":"设备数量",
					   "comment":"备注"
				   },"text":{
					   "id":obj.id,
					   "equipment_name":obj.equipment_name,
					   "equipment_num":obj.equipment_num,
					   "comment":obj.comment=="null"?"":obj.comment
				   },"input":{
					   "id":"hidden",
					   "equipment_name":"text_readonly",
					   "equipment_num":"text",
					   "comment":"text"
				   },"input_init":{
				   }
		   };
		   var getDiv = dc_update.innerHTML;
		   laytpl(getDiv).render(data,function(html){
			   content = html;
		   });
		   return content;
	   }
	   layopen(contentDIV());
   }
   
   var layopen = function(content){
		layer.open({
		  	title:'更新设备配备'
			,content: content
	    	,area: ['800px', '700px']
		    ,scrollbar: false
		  	,btn: ['确认', '取消']
			,yes: function(index,layero){ //确认
		  	    var data = $(layero).find("form").serializeJSON();
		  	    if(verify_data(data)){
					$.post(base+"/projectCenter/businessdata/updateEquipmentEquipInfo",{
						id:data.id==null?"":data.id,
						equipment_id:$.trim(data.equipment_id),
						equipment_num:$.trim(data.equipment_num),
						equipment_equip_id:$.trim($("#equip_id").val()),
						equipment_name:$.trim($("select[name='equipment_id'] option:selected").text()),
						comment:$.trim(data.comment)
					},
			  		function (data,status){
						if(data!=""&&data!=null){
							if(data.statusCode == 0){
								layer.msg('更新成功', {icon: 1,time:2000});
							}else{
								layer.msg(data.message, {icon: 2,time:2000});
							}
						}else{
							layer.msg('更新失败!', {icon: 2,time:2000});
						}
						initData(1);
			  		 })
		  	    }
			}
	});
}
   
   var delObj = function(obj){
	   layer.confirm('确认删除?',{btn : [ '确定', '取消' ]},function(index){
		   layer.close(index);
		   var param = {id:obj.id}
		   $.ajax({
			   url:base+"/projectCenter/businessdata/delEquipmentEquipInfoById",
			   data:param,
			   success:function(data,status){
				    if(data.statusCode == 0){
						layer.msg(data.message, {
							icon : 1
						});
				    }else{
						layer.msg(data.message, {
							icon : 5
						});
				    }
				    initData(1);
			   }
		   });
	   });
   }
   
   var verify_data = function(data){
		if(data.equipment_type_id == ""){
			alert("请选择设备类型!");
			return false;
		}
		if(data.equipment_cid_type_id == ""){
			alert("请选择设备子类型！");
			return false;
		}
		if(data.equipment_id == ""){
			alert("请选择设备!");
			return false;
		}
		if(data.equipment_num == ""){
			alert("请选择设备数量!");
			return false;
		}
		if(data.equipment_manufacturer_id == ""){
			alert("请选择设备厂商!")
			return false;
		}
		if(data.equipment_price == ""){
			alert("请选择设备单价!")
			return false;
		}
	   return true;
  }
   
   //开始设备选型
   var equipmentSelection = function(obj){
	   var contentDIV = function(){
		   var content;
		   var data = {
				   "title":{
					   "id":"id",
					   "equipment_name":"设备名称",
					   "equipment_num":"设备数量",
					   "equipment_manufacturer_id":"所属厂商",
					   "equipment_price":"设备单价"
				   },"text":{
					   "id":obj.id,
					   "equipment_name":obj.equipment_name,
					   "equipment_num":obj.equipment_num,
					   "equipment_manufacturer_id":"",
					   "equipment_price":obj.equipment_price
				   },"input":{
					   "id":"hidden",
					   "equipment_name":"text_readonly",
					   "equipment_num":"text_readonly",
					   "equipment_manufacturer_id":"_select",
					   "equipment_price":"text"
				   },"input_init":{
				   }
		   };
		   var getDiv = dc_update.innerHTML;
		   laytpl(getDiv).render(data,function(html){
			   content = html;
		   });
		   return content;
	   }
		layer.open({
		  	title:'设备选型'
			,content: contentDIV()
	    	,area: ['800px', '700px']
		    ,scrollbar: false
		  	,btn: ['确认', '取消']
			,yes: function(index,layero){ //确认
		  	    var data = $(layero).find("form").serializeJSON();
		  	    if(verify_data(data)){
					$.post(base+"/projectCenter/businessdata/equipmentSelection",{
						id:data.id==null?"":data.id,
						equipment_manufacturer_id:data.equipment_manufacturer_id,
						equipment_price:data.equipment_price
					},
			  		function (data,status){
						if(data!=""&&data!=null){
							if(data.statusCode == 0){
								layer.msg('更新成功', {icon: 1,time:2000});
							}else{
								layer.msg(data.message, {icon: 2,time:2000});
							}
						}else{
							layer.msg('更新失败!', {icon: 2,time:2000});
						}
						initData(1);
			  		 })
		  	    }
			}
	});
		initManufacturer(obj.equipment_id,obj.equipment_manufacturer_id);
		chanageManufacturer(obj.equipment_id);
   }

   
   //初始化设备所属厂商
   var initManufacturer = function(equipment_id,manufacturer_id){
	   $.post(base+"/dataCenter/businessdata/findManufacturerListByEquipmentId",{equipment_id:equipment_id},
	   		  	function(data,status){
   		    	if(data != null){
 	      		  	 var optionstring = "";
 	                 $.each(data, function(i,item){
 	                	 if(item.equipment_manufacturer_id == manufacturer_id){
 	                		optionstring += "<option selected='selected' value=\"" + item.equipment_manufacturer_id + "\" >" + item.equipment_manufacturer_name + "</option>";
 	                	 }else{
 	                		optionstring += "<option value=\"" + item.equipment_manufacturer_id + "\" >" + item.equipment_manufacturer_name + "</option>";
 	                	 }
 	                });
 	                $("select[name='equipment_manufacturer_id']").html('<option value=""></option>' + optionstring);
 	      		}else{
 	      		  	$("select[name='equipment_manufacturer_id']").html('<option value=""></option>');
 	      		}
   		    form.render(); 
	  });
   }
   
   //监听厂商选择
   var chanageManufacturer = function(equipment_id){
 		form.on("select(_select)",function(value){
   			var manufacturer_id = value.value;
   			initEquipmentPrice(equipment_id,manufacturer_id);
   		});
   }
   
   //初始化设备价格
   var initEquipmentPrice = function(equipment_id , manufacturer_id){
	   $.post(base+"/dataCenter/businessdata/findManufacturerEquipmentPageList",{equipment_id:equipment_id,
		   manufacturer_id:manufacturer_id},
	   		  	function(data,status){
  		    	if(data != null){
  		    		var data_list = data.list;
  		    		$("input[name='equipment_price']").val(data_list[0].equipment_price);
	      		}else{
	      		  	$("input[name='equipment_price']").val("");
	      		}
  		    form.render(); 
	  });
   }
   
   //初始化设备类型
   var _initEquipmenType = function(){
	   $.post(base+"/dataCenter/businessdata/findEquipmentType",{},
	   		  	function(data,status){
   		    	if(data != null && data.list != null){
 	      		  	 var optionstring = "";
 	                 $.each(data.list, function(i,item){
 	                	optionstring += "<option value=\"" + item.id + "\" >" + item.equipment_type_name + "</option>";
 	                });
 	                $("#equipment_type").html('<option value="">请选择设备类型</option>' + optionstring);
 	      		}else{
 	      		  	$("#equipment_type").html('<option value="">请选择设备类型</option>');
 	      		}
	  });
   }
   
   //初始化设备子类型
   var _initEquipmentCidType = function(equipment_type_id){
	   $.post(base+"/dataCenter/businessdata/findEquipmentCidTypeList",{equipment_type_id:equipment_type_id},
	   		  	function(data,status){
   		    	if(data != null && data.list != null){
 	      		  	 var optionstring = "";
 	                 $.each(data.list, function(i,item){
 	                	optionstring += "<option value=\"" + item.id + "\" >" + item.equipment_children_type_name + "</option>";
 	                });
 	                $("#equipment_child_type").html('<option value="">请选择设备子类型</option>' + optionstring);
 	      		}else{
 	      		  	$("#equipment_child_type").html('<option value="">请选择设备子类型</option>');
 	      		}
	  });
   }
   
   var query_type = "";
   var equipment_type_id = "";
 
   //设备类型选择事件
   var equipment_type_change = function(){
	   var val = $(this).children('option:selected').val();
	   var text = $(this).children('option:selected').text();
	   _initEquipmentCidType(val);//初始化子设备列表
	   query_type = "equipment_type";
	   equipment_type_id = val;
	   if(val == ""){
		   initData(1);
	   }else{
		   showData(1);
	   }
   }
   
   //设备子类型选择事件
   var equipment_child_type_change = function(){
	   var val = $(this).children('option:selected').val();
	   var text = $(this).children('option:selected').text();
	   //刷新数据
	   query_type = "equipment_child_type";
	   equipment_type_id = val;
	   showData(1);
   }
   
   var editEquipmentNum = function(obj){
	   var contentDIV = function(){
		   var content;
		   var data = {
				   "title":{
					   "id":"id",
					   "equipment_id":"设备id",
					   "equipment_name":"设备名称",
					   "equipment_num":"设备数量",
					   "equipment_equip_id":"所属设备配备"
				   },"text":{
					   "id":obj.equipment_equip_info_id=="null"?"":obj.equipment_equip_info_id,
					   "equipment_id":obj.id,
					   "equipment_name":obj.equipment_name,
					   "equipment_num":obj.equipment_num=="null"?"":obj.equipment_num,
					   "equipment_equip_id":$.trim($("#equip_id").val())
				   },"input":{
					   "id":"hidden",
					   "equipment_id":"hidden",
					   "equipment_name":"text",
					   "equipment_num":"text",
					   "equipment_equip_id":"hidden"
				   },"input_init":{
				   }
		   };
		   var getDiv = dc_update.innerHTML;
		   laytpl(getDiv).render(data,function(html){
			   content = html;
		   });
		   return content;
	   }
		layer.open({
		  	title:'编辑设备数量'
			,content: contentDIV()
	    	,area: ['800px', '700px']
		    ,scrollbar: false
		  	,btn: ['确认', '取消']
			,yes: function(index,layero){ //确认
		  	    var data = $(layero).find("form").serializeJSON();
		  	    if(data.equipment_name == "" || data.equipment_num == ""){
		  	    	alert("缺少参数!")
		  	    	return false;
		  	    }
				$.post(base+"/projectCenter/businessdata/updateEquipmentEquipInfo",data,
		  		function (data,status){
					if(data!=""&&data!=null){
						if(data.statusCode == 0){
							layer.msg('更新成功', {icon: 1,time:2000});
						}else{
							layer.msg(data.message, {icon: 2,time:2000});
						}
					}else{
						layer.msg('更新失败!', {icon: 2,time:2000});
					}
					initData(1);
		  		 })
			}
	});
	   
	   return null;
   }
   
   //刷新所有设备
   var showData = function(num){
	    var url = base+"/projectCenter/businessdata/findEquipmentByTypeId";
	    var param = {
				page_num:num,
				page_size:"10",
				query_type:query_type,
				equipment_type_id:equipment_type_id,
				equip_id:$.trim($("#equip_id").val())
		    }
	    $.post(url,param,function(data,status){
        	if(data != null){
        		//alert(JSON.stringify(data));
	        	var pageCount = data.pager.pageCount;
	        	var dataObj ={
	        			"list":data.list,
	         			"dataTool":{
	         				"title":{
	          			      	"equipment_children_type_name": "设备类型名称"
	          			      	,"equipment_name": "设备名称"
	          			      	,"equipment_num":"设备数量" //新建设备配备信息时初始化的某种设备配备的设备数量
	          			      	,"create_time":"创建时间"
	          			      	,"update_time":"修改时间"
	          			      	,"operation":"操作"
	            			},
	            			"titleCheckbox":false,
							"btn":[{"event":"editEquipmentNum","name":"编辑"}]
	            			}
		  		};
	        	showPageTable('view', dataObj,num,pageCount,"showData");
        	}
	    });
   }
   
   //一键选型
   $("#defaultModel").click(function(){
	   layer.confirm('确认一键选型?',{btn : [ '确定', '取消' ]},function(index){
		   layer.close(index);
		   var load_index = layer.load(1, {shade: [0.1,'#fff'],scrollbar: false});
		   var url = base+"/projectCenter/businessdata/allEquipmentEquip";
		   var param = {
				   equip_id:$.trim($("#equip_id").val())
		   }
		   $.ajax({
			   url:url,
			   data:param,
			   success:function(data,status){
				    layer.close(load_index);
				    if(data.statusCode == 0){
						layer.msg(data.message, {
							icon : 1
						});
				    }else{
						layer.msg(data.message, {
							icon : 5
						});
				    }
				    initData(1);
			   }
		   });
	   });
   });
   
   //对设备要求高亮处理,鼠标移动上去有悬浮提示
   var equipment_require_init = function(){
	   $.each($("tbody").children("tr"),function(index,value){
		   if(index > 0){
			   var sign_element;
			   var tr_element = $(this);
			   $.each(tr_element.children("td"),function(cid_index,value){
				   var td_element = $(this);
				   if(td_element.attr("field") == "equipment_name"){
					   sign_element = $(this);
				   }
				   if($(this).attr("field") == "equipment_num_for_185" && $.trim($(this).text()) != ""){
					   var equipment_require = $.trim($(this).text());
					   sign_element.html("<span class='self-examination-fail'>"+sign_element.text()+"</span>");
					   //绑定鼠标悬浮提示
					   sign_element.mouseenter(function(){
						   layer.tips(equipment_require, sign_element, {
							   tips: [2, '#78BA32'],
							   time: 4000
							 });
					   });
					   return false;
				   }
				   
			   })
		   }
	   });
   }
   
   $(document).ready(function(){
	   initData(1);
	   //对设备要求高亮
	   $("#addData").click(addData)
	   $("#searchInfo").click(searchData);
	   $("#equipment_type").change(equipment_type_change);
	   $("#equipment_child_type").change(equipment_child_type_change);
	   _initEquipmenType();
   });

   